package com.example.moblie2030606150cjk0401;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private ImageView ivMainLight;
    private Button btnMainLightOn;
    private Button btnMainLightOff;
    private Button btnMainFanOn;
    private Button btnMainlin;
    int a = 0;
    int i = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        btnMainlin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (a){
                    case 0:tvMainTitle.setBackgroundResource(R.drawable.line_01);break;
                    case 1:tvMainTitle.setBackgroundResource(R.drawable.line_02);break;
                    case 2:tvMainTitle.setBackgroundResource(R.drawable.line_03);break;
                    case 3:tvMainTitle.setBackgroundResource(R.drawable.line_04);break;
                    case 4:tvMainTitle.setBackgroundResource(R.drawable.line_05);break;
                    case 5:tvMainTitle.setBackgroundResource(R.drawable.line_06);break;
                }
                if (a >= 6)
                    a=0;
            }
        });

        btnMainFanOn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                i++;
                if (i % 2 == 0) {
                    ivMainLight.setImageResource(R.drawable.fan_on);
                } else {
                    ivMainLight.setImageResource(R.drawable.fan_off);
                }


            }
        });

        btnMainLightOn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivMainLight.setImageResource(R.drawable.light_on);

            }
        });
        btnMainLightOff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivMainLight.setImageResource(R.drawable.light_off);
            }
        });
    }

    private void initView() {

        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        ivMainLight = (ImageView) findViewById(R.id.iv_main_light);
        btnMainLightOn = (Button) findViewById(R.id.btn_main_lightOn);
        btnMainLightOff = (Button) findViewById(R.id.btn_main_lightOff);
        btnMainFanOn = (Button) findViewById(R.id.btn_main_fanon);
        btnMainlin = (Button) findViewById(R.id.btn_main_line);

    }
}